package com.eff.android.fragment.main.start;

import java.util.ArrayList;
import java.util.List;

import com.eff.android.R;
import com.eff.android.lib.ui.ECustomAdapter;
import com.eff.android.lib.ui.ECustomDialogHelp;
import com.eff.android.lib.ui.ERowItem;

import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ImageButton;
import android.widget.ListView;
import android.view.View.OnClickListener;;

public class EMainFragmentPronounciation extends Fragment
implements OnItemLongClickListener{

	public static final String TAG = EMainFragmentPronounciation.class.getSimpleName();
	
	ListView imgList;	
	String[] menuTitles;
    TypedArray eImages;

    ECustomAdapter eAdapter;
    private List<ERowItem> rowItems;
    
    ImageButton speaker;
	
	public static EMainFragmentPronounciation newInstance(Context context, Bundle b) {
		EMainFragmentPronounciation f = new EMainFragmentPronounciation();
		if (b != null){
		    f.setArguments(b);
		}
		return f;
	}

	public static Bundle getArgs() {
		Bundle b = new Bundle();
		b.putString(TAG, TAG);
		return b;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		initFragments();
	}

	private void initFragments() {
		// TODO Auto-generated method stub
		
	}
	
	@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
	    Bundle savedInstanceState) {
		super.onCreateView(inflater, container, savedInstanceState);
		
		View v = inflater.inflate(R.layout.e_frm_main_start_pronunciation, container, false);
		initViews(v);
		    
		return v;
    }
	
	private void initRowItems(){
		menuTitles = getResources().getStringArray(R.array.titles);
        eImages = getResources().obtainTypedArray(R.array.icons);
		
		rowItems = new ArrayList<ERowItem>();

        for (int i = 0; i < menuTitles.length; i++) {
           ERowItem items = new ERowItem(menuTitles[i], eImages.getResourceId(i, -1));
           rowItems.add(items);
        }
	}

	private void initViews(View v) {
		imgList = (ListView) v.findViewById(R.id.list);
		initRowItems();
		
		eAdapter = new ECustomAdapter(getActivity(), rowItems);
        imgList.setAdapter(eAdapter);
        imgList.setOnItemLongClickListener(this);
	}

	@Override
	public boolean onItemLongClick(AdapterView<?> parent, View view,
			int position, long id) {
		
		final ECustomDialogHelp dialog = new ECustomDialogHelp(view.getContext());
		dialog.show();
		
		speaker = (ImageButton) dialog.findViewById(R.id.btnSpeaker);
	    speaker.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// nghe phat am mau o day
				
			}
		});
	    
	    return true;
	}

}
